

package com.hazelcast.internal.management.operation;

import com.hazelcast.spi.impl.NodeEngine;
import com.hazelcast.spi.impl.operationservice.AbstractLocalOperation;
import com.hazelcast.wan.WanPublisherState;
import com.hazelcast.wan.impl.WanReplicationService;

/**
 * Stop, pause or resume WAN replication for the given {@code wanReplicationName} and {@code wanPublisherId}.
 */
public class ChangeWanStateOperation extends AbstractLocalOperation {

    private String wanReplicationName;
    private String wanPublisherId;
    private WanPublisherState state;

    public ChangeWanStateOperation(String wanReplicationName, String wanPublisherId, WanPublisherState state) {
        this.wanReplicationName = wanReplicationName;
        this.wanPublisherId = wanPublisherId;
        this.state = state;
    }

    @Override
    public void run() throws Exception {
        NodeEngine nodeEngine = getNodeEngine();
        WanReplicationService wanReplicationService = nodeEngine.getWanReplicationService();

        switch (state) {
        case REPLICATING:
            wanReplicationService.resume(wanReplicationName, wanPublisherId);
            break;
        case PAUSED:
            wanReplicationService.pause(wanReplicationName, wanPublisherId);
            break;
        case STOPPED:
            wanReplicationService.stop(wanReplicationName, wanPublisherId);
            break;
        default:
            break;
        }
    }
}
